home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / schur.cc < prev    next >
C/C++ Source or Header  |  1996-11-03  |  3KB  |  154 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #ifdef HAVE_CONFIG_H
  24. #include <config.h>
  25. #endif
  26.  
  27. #include <string>
  28.  
  29. #include "CmplxSCHUR.h"
  30. #include "dbleSCHUR.h"
  31.  
  32. #include "defun-dld.h"
  33. #include "error.h"
  34. #include "gripes.h"
  35. #include "help.h"
  36. #include "oct-obj.h"
  37. #include "utils.h"
  38.  
  39. DEFUN_DLD (schur, args, nargout,
  40.   "[U, S] = schur (A) or S = schur (A)\n\
  41. \n\
  42. or, for ordered Schur:\n\
  43. \n\
  44.   [U, S] = schur (A, TYPE) or S = schur (A, TYPE)\n\
  45. where TYPE is a string that begins with one of the following\n\
  46. characters:\n\
  47. \n\
  48.   A = continuous time poles\n\
  49.   D = discrete time poles\n\
  50.   U = unordered schur (default)")
  51. {
  52.   octave_value_list retval;
  53.  
  54.   int nargin = args.length ();
  55.  
  56.   if (nargin < 1 || nargin > 2 || nargout > 2)
  57.     {
  58.       print_usage ("schur");
  59.       return retval;
  60.     }
  61.  
  62.   octave_value arg = args(0);
  63.  
  64.   string ord;
  65.  
  66.   if (nargin == 2)
  67.     {
  68.       ord = args(1).string_value (); 
  69.  
  70.       if (error_state)
  71.     {
  72.       error ("schur: expecting string as second argument");
  73.       return retval;
  74.     }
  75.     }
  76.  
  77.   char ord_char = ord.empty () ? 'U' : ord[0];
  78.  
  79.   if (ord_char != 'U' && ord_char != 'A' && ord_char != 'D'
  80.       && ord_char != 'u' && ord_char != 'a' && ord_char != 'd')
  81.     {
  82.       warning ("schur: incorrect ordered schur argument `%c'",
  83.            ord.c_str ());
  84.       return retval;
  85.     }
  86.  
  87.   int nr = arg.rows ();
  88.   int nc = arg.columns ();
  89.  
  90.   int arg_is_empty = empty_arg ("schur", nr, nc);
  91.  
  92.   if (arg_is_empty < 0)
  93.     return retval;
  94.   else if (arg_is_empty > 0)
  95.     return octave_value_list (2, Matrix ());
  96.  
  97.   if (nr != nc)
  98.     {
  99.       gripe_square_matrix_required ("schur");
  100.       return retval;
  101.     }
  102.  
  103.   if (arg.is_real_type ())
  104.     {
  105.       Matrix tmp = arg.matrix_value ();
  106.  
  107.       if (! error_state)
  108.     {
  109.       SCHUR result (tmp, ord);
  110.  
  111.       if (nargout == 0 || nargout == 1)
  112.         {
  113.           retval(0) = result.schur_matrix ();
  114.         }
  115.       else
  116.         {
  117.           retval(1) = result.schur_matrix ();
  118.           retval(0) = result.unitary_matrix ();
  119.         }
  120.     }
  121.     }
  122.   else if (arg.is_complex_type ())
  123.     {
  124.       ComplexMatrix ctmp = arg.complex_matrix_value ();
  125.  
  126.       if (! error_state)
  127.     {
  128.       ComplexSCHUR result (ctmp, ord);
  129.  
  130.       if (nargout == 0 || nargout == 1)
  131.         {
  132.           retval(0) = result.schur_matrix ();
  133.         }
  134.       else
  135.         {
  136.           retval(1) = result.schur_matrix ();
  137.           retval(0) = result.unitary_matrix ();
  138.         }
  139.     }
  140.     }    
  141.   else
  142.     {
  143.       gripe_wrong_type_arg ("schur", arg);
  144.     }
  145.  
  146.   return retval; 
  147. }
  148.  
  149. /*
  150. ;;; Local Variables: ***
  151. ;;; mode: C++ ***
  152. ;;; End: ***
  153. */
  154.